Distributions cannot be freed by garbage collector due to self-references #13986
Labels
defect
A clear bug or issue that prevents SciPy from being installed or used as expected
scipy.stats
I believe that continuous distributions in
scipy.stats.distributions
cannot be freed by the garbage collector due to self references in therv_continuous
base class implementation.Reproducing code example:
Need to download objgraph
This will produce two plots, one that shows the references keeping the leaky list in memory and one that shows the references keeping the uniform distribution in memory despite both being deleted. As a sanity check, I assert that the non-leaky list is never present in
gc.garbage
.Leaky list back references
To also sanity check the objgraph output, I display the references keeping the leaky list in memory. There's a self-reference displayed, which makes sense.
Uniform distribution back references
We see that the
np.vectorize
'd methods (self._ppf_single_call
,self._entropy
,self._cdf_single_call
,self._mom1_sc
) and the_parse_args
methods have references to the uniform distribution, despite being created by the uniform distribution!I found that surprising! I wonder if the way the
np.vectorize
calls and the_parse_args
methods can be refactored to avoid self-references. I don' think it's ideal that these distributions will never be released from memory by the garbage collector.Scipy/Numpy/Python version information:
The text was updated successfully, but these errors were encountered: